<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品ID" prop="productId">
        <id-selector
          v-model="queryParams.productId"
          placeholder="请选择商品"
          dialog-title="选择商品"
          :api-function="listProduct"
          :get-api-function="getProduct"
          id-field="productId"
          name-field="productName"
          id-label="商品ID"
          name-label="商品名称"
          search-label="商品名称"
          search-placeholder="请输入商品名称"
          :extra-columns="[{prop: 'categoryName', label: '分类'}, {prop: 'brandName', label: '品牌'}, {prop: 'price', label: '价格'}]"
        />
      </el-form-item>
      <el-form-item label="编码" prop="skuCode">
        <el-input
          v-model="queryParams.skuCode"
          placeholder="请输入SKU编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="skuName">
        <el-input
          v-model="queryParams.skuName"
          placeholder="请输入SKU名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库存" prop="stock">
        <el-input
          v-model="queryParams.stock"
          placeholder="请输入库存数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="会员专享" prop="isVipBuy">
        <el-select v-model="queryParams.isVipBuy" placeholder="请选择是否会员专享" clearable>
          <el-option label="是" :value="1" />
          <el-option label="否" :value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="购买白名单" prop="buyWhiteList">
        <el-input
          v-model="queryParams.buyWhiteList"
          placeholder="请输入购买白名单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['fun:sku:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-copy-document"
          size="mini"
          @click="handleCopyAdd"
          v-hasPermi="['fun:sku:add']"
        >复制新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['fun:sku:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['fun:sku:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fun:sku:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['fun:sku:import']"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="skuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="SKU ID" align="center" prop="skuId" width="80" />
      <el-table-column label="SKU编码" align="center" prop="skuCode" width="150">
        <template slot-scope="scope">
          <el-link type="primary" @click="handleUpdate(scope.row)" :underline="false">
            {{ scope.row.skuCode }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="商品" align="center" prop="productName" width="150" show-overflow-tooltip />
      <el-table-column label="创建组织" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ getDeptName(scope.row.orgId) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="SKU名称" align="center" prop="skuName" width="150" show-overflow-tooltip />
      <el-table-column label="规格信息" align="center" prop="specInfo" width="200">
        <template slot-scope="scope">
          <div v-if="scope.row.specInfo">
            <el-tag
              v-for="(value, key) in parseSpecInfo(scope.row.specInfo)"
              :key="key"
              type="primary"
              plain
              size="mini"
              style="margin: 2px;"
            >
              {{ key }}: {{ value }}
            </el-tag>
          </div>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="价格" align="center" prop="price" width="80" />
      <el-table-column label="原价" align="center" prop="originalPrice" width="80" />
      <el-table-column label="成本价" align="center" prop="costPrice" width="80" />
      <el-table-column label="库存数量" align="center" prop="stock" width="80" />
      <el-table-column label="库存预警值" align="center" prop="lowStock" width="100" />
      <!-- <el-table-column label="重量" align="center" prop="weight" width="80" /> -->
      <!-- <el-table-column label="体积" align="center" prop="volume" width="80" /> -->
      <el-table-column label="SKU图片" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="销量" align="center" prop="saleCount" width="80" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="会员专享" align="center" prop="isVipBuy" width="100">
        <template slot-scope="scope">
          <el-tag :type="scope.row.isVipBuy === 1 ? 'warning' : 'info'" size="mini">
            {{ scope.row.isVipBuy === 1 ? '是' : '否' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="购买白名单" align="center" prop="buyWhiteList" width="150">
        <template slot-scope="scope">
          <el-link 
            type="primary" 
            @click="handleViewWhitelist(scope.row)" 
            :underline="false"
            v-if="scope.row.buyWhiteList"
          >
            查看白名单
          </el-link>
          <el-link 
            type="primary" 
            @click="handleViewWhitelist(scope.row)" 
            :underline="false"
            v-else
          >
            查看白名单
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['fun:sku:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fun:sku:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品SKU对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商品" prop="productId">
          <id-selector
            v-model="form.productId"
            placeholder="请选择商品"
            dialog-title="选择商品"
            :api-function="listProduct"
            :get-api-function="getProduct"
            id-field="productId"
            name-field="productName"
            id-label="商品ID"
            name-label="商品名称"
            search-label="商品名称"
            search-placeholder="请输入商品名称"
            :extra-columns="[{prop: 'productCode', label: '商品编码'}, {prop: 'price', label: '价格'}]"
          />
        </el-form-item>
        <el-form-item label="SKU编码" prop="skuCode">
          <coding-input
            v-model="form.skuCode"
            table-name="fun_sku"
            field-name="sku_code"
            :enable-auto-generate="true"
            :show-preview="true"
            :show-refresh="true"
            :is-edit="isEdit"
            placeholder="请输入SKU编码或点击生成"
            @code-generated="handleCodeGenerated"
          />
        </el-form-item>
        <el-form-item label="SKU名称" prop="skuName">
          <el-input v-model="form.skuName" placeholder="请输入SKU名称" />
        </el-form-item>
        <el-form-item label="规格信息" prop="specInfo">
          <el-input v-model="form.specInfo" placeholder="请输入规格信息" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="原价" prop="originalPrice">
          <el-input v-model="form.originalPrice" placeholder="请输入原价" />
        </el-form-item>
        <el-form-item label="成本价" prop="costPrice">
          <el-input v-model="form.costPrice" placeholder="请输入成本价" />
        </el-form-item>
        <el-form-item label="库存数量" prop="stock">
          <el-input v-model="form.stock" placeholder="请输入库存数量" />
        </el-form-item>
        <!-- <el-form-item label="低库存预警" prop="lowStock">
          <el-input v-model="form.lowStock" placeholder="请输入低库存预警值" />
        </el-form-item> -->
        <el-form-item label="重量" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入重量" />
        </el-form-item>
        <el-form-item label="体积" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入体积" />
        </el-form-item>
        <el-form-item label="图片" prop="image">
          <el-input v-model="form.image" placeholder="请输入图片URL" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_common_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="会员专享" prop="isVipBuy">
          <el-radio-group v-model="form.isVipBuy">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="购买白名单" prop="buyWhiteList">
          <el-input v-model="form.buyWhiteList" placeholder="请输入购买白名单，多个用户用逗号分隔" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- SKU导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的SKU数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 购买白名单编辑弹窗 -->
    <el-dialog 
      title="编辑购买白名单" 
      :visible.sync="whitelistDialog.open" 
      width="600px" 
      append-to-body
    >
      <div style="margin-bottom: 15px;">
        <strong>SKU信息：</strong>{{ whitelistDialog.skuName }} ({{ whitelistDialog.skuCode }})
      </div>
      <div style="display: flex; align-items: flex-start; gap: 10px;">
        <id-selector
          v-model="whitelistDialog.selectedUserIds"
          placeholder="请选择用户"
          dialog-title="选择用户"
          :api-function="listUser"
          :get-api-function="getUser"
          id-field="userId"
          name-field="userName"
          id-label="用户ID"
          name-label="用户名称"
          search-label="用户名称"
          search-placeholder="请输入用户名称"
          :extra-columns="[{prop: 'nickName', label: '昵称'}, {prop: 'email', label: '邮箱'}]"
          :multiple="true"
          style="flex: 1;"
        />
        <el-button 
          type="danger" 
          size="small" 
          icon="el-icon-delete" 
          @click="clearWhitelistSelection"
          title="清空选择"
        >
          清空
        </el-button>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSaveWhitelist" :loading="whitelistDialog.loading">确 定</el-button>
        <el-button @click="whitelistDialog.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSku, getSku, delSku, addSku, updateSku, importData, importTemplate } from "@/api/fun/sku";
import { getDept } from "@/api/system/dept"
import CacheManager from '@/utils/cacheManager'
import { listProduct, getProduct } from "@/api/fun/product"
import { listUser, getUser } from "@/api/system/user"
import IdSelector from "@/components/IdSelector"
import CodingInput from '@/components/CodingInput'

export default {
  name: "Sku",
  components: {
    IdSelector,
    CodingInput
  },
  dicts: ['sys_common_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品SKU表格数据
      skuList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 是否编辑模式
      isEdit: false,
      // 表单校验
      rules: {
        productId: [
          { required: true, message: "商品ID不能为空", trigger: "blur" }
        ],
        skuCode: [
          { required: true, message: "SKU编码不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "价格不能为空", trigger: "blur" }
        ],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productId: null,
        skuCode: null,
        skuName: null,
        specInfo: null,
        price: null,
        originalPrice: null,
        costPrice: null,
        stock: null,
        lowStock: null,
        weight: null,
        volume: null,
        image: null,
        saleCount: null,
        status: null,
        isVipBuy: null,
        buyWhiteList: null,
      },
      // 导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的SKU数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + this.$store.getters.token },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/fun/sku/importData"
      },
      // 购买白名单弹窗参数
      whitelistDialog: {
        open: false,
        loading: false,
        skuId: null,
        skuCode: '',
        skuName: '',
        selectedUserIds: []
      }
    }
  },
  created() {
    // 检查路由参数中是否有productId
    if (this.$route.query.productId) {
      this.queryParams.productId = this.$route.query.productId
    }
    this.getList()
  },
  mounted() {
    // 监听表单提交事件
    this.$eventBus.$on('refreshSkuList', () => {
      this.getList()
    })
  },
  beforeDestroy() {
    // 移除事件监听器
    this.$eventBus.$off('refreshSkuList')
  },
  methods: {    /** 根据部门ID获取部门名称 */
    getDeptName(deptId) {
      return CacheManager.getDeptName(deptId, getDept)
    },
    /** 查询商品SKU列表 */
    getList() {
      this.loading = true
      listSku(this.queryParams).then(response => {
        this.skuList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        skuId: null,
        productId: null,
        skuCode: null,
        skuName: null,
        specInfo: null,
        price: null,
        originalPrice: null,
        costPrice: null,
        stock: null,
        lowStock: 0,
        weight: null,
        volume: null,
        image: null,
        saleCount: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.skuId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      const query = { pageType: "add" };
      // 如果页面有productId参数或过滤框中有商品ID，自动带入到新增表单中
      const productId = this.$route.query.productId || this.queryParams.productId;
      if (productId) {
        query.productId = productId;
      }
      const obj = { path: "/fun/sku/form", query: query };
      this.$tab.openPage("新增商品SKU", obj.path, obj.query);
    },
    /** 复制新增按钮操作 */
    handleCopyAdd() {
      // 检查选中行数
      const selection = this.skuList.filter(item => this.ids.includes(item.skuId));
      if (selection.length === 0) {
        this.$modal.msgError("请先选择要复制的数据，然后点击复制新增按钮");
        return;
      }
      if (selection.length > 1) {
        this.$modal.msgError("复制新增功能只能选择一条数据，请重新选择");
        return;
      }

      // 获取选中的SKU数据
      const selectedSku = selection[0];

      // 构建复制数据，排除skuId和skuCode
      const copyData = {
        productId: selectedSku.productId,
        skuName: selectedSku.skuName,
        specInfo: selectedSku.specInfo,
        price: selectedSku.price,
        originalPrice: selectedSku.originalPrice,
        costPrice: selectedSku.costPrice,
        stock: selectedSku.stock,
        lowStock: selectedSku.lowStock,
        weight: selectedSku.weight,
        volume: selectedSku.volume,
        image: selectedSku.image,
        status: selectedSku.status
      };

      // 将复制数据编码为base64传递
      const copyDataStr = btoa(encodeURIComponent(JSON.stringify(copyData)));
      const query = {
        pageType: "add",
        copyData: copyDataStr
      };

      const obj = { path: "/fun/sku/form", query: query };
      this.$tab.openPage("复制新增商品SKU", obj.path, obj.query);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const skuId = row.skuId || this.ids;
      const obj = { path: "/fun/sku/form", query: { pageType: "edit", skuId: skuId } };
      this.$tab.openPage("修改商品SKU", obj.path, obj.query);
    },

    /** 编码生成回调 */
    handleCodeGenerated(code) {
      console.log('生成的SKU编码:', code)
      // 可以在这里处理编码生成后的逻辑
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.skuId != null) {
            updateSku(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
              // 刷新父页面数据
              this.$tab.refreshPage()
            })
          } else {
            addSku(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
              // 刷新父页面数据
              this.$tab.refreshPage()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const skuIds = row.skuId || this.ids
      this.$modal.confirm('是否确认删除商品SKU编号为"' + skuIds + '"的数据项？').then(function() {
        return delSku(skuIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fun/sku/export', {
        ...this.queryParams
      }, `sku_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "SKU导入"
      this.upload.open = true
    },
    /** 下载模板操作 */
    importTemplate() {
      const link = document.createElement('a')
      link.href = process.env.BASE_URL + 'templates/sku_import_template.xlsx'
      link.download = `sku_template_${new Date().getTime()}.xlsx`
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    /** 解析规格信息JSON */
    parseSpecInfo(specInfo) {
      try {
        if (typeof specInfo === 'string') {
          return JSON.parse(specInfo)
        }
        return specInfo || {}
      } catch (e) {
        console.warn('解析规格信息失败:', e)
        return {}
      }
    },
    /** 处理编码生成 */
    handleCodeGenerated(code) {
      this.form.skuCode = code
    },
    /** 查看购买白名单 */
    handleViewWhitelist(row) {
      this.whitelistDialog.open = true
      this.whitelistDialog.skuId = row.skuId
      this.whitelistDialog.skuCode = row.skuCode
      this.whitelistDialog.skuName = row.skuName
      
      // 解析现有的购买白名单
      if (row.buyWhiteList) {
        this.whitelistDialog.selectedUserIds = row.buyWhiteList.split(',').filter(id => id.trim()).map(id => parseInt(id.trim()))
      } else {
        this.whitelistDialog.selectedUserIds = []
      }
    },
    /** 保存购买白名单 */
    handleSaveWhitelist() {
      this.whitelistDialog.loading = true
      
      // 构建更新数据
      const updateData = {
        skuId: this.whitelistDialog.skuId,
        buyWhiteList: this.whitelistDialog.selectedUserIds.length > 0 ? this.whitelistDialog.selectedUserIds.join(',') : ''
      }
      
      updateSku(updateData).then(response => {
        this.$modal.msgSuccess("购买白名单更新成功")
        this.whitelistDialog.open = false
        this.whitelistDialog.loading = false
        this.getList() // 刷新列表
      }).catch(() => {
        this.whitelistDialog.loading = false
      })
    },
    /** 清空白名单选择 */
    clearWhitelistSelection() {
      this.whitelistDialog.selectedUserIds = []
    },
    // API方法
    listProduct,
    getProduct,
    listUser,
    getUser
  }
}
</script>
